﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using University.Workshop.Presenters;

namespace University.Workshop.WinApp.CashManagementFolder
{
    public partial class CashManagementForm : Form
    {
        public string PatientId;
        public string DoctorId;
        public string AppointmentId;
        public string DateAppointment;


        public CashManagementForm()
        {
            InitializeComponent();
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string anios = dateTimePickerPayment.Value.Year.ToString();
                string meses = dateTimePickerPayment.Value.Month.ToString();
                string dias = dateTimePickerPayment.Value.Day.ToString();
                string fecha = anios + "/" + meses + "/" + dias;

                CashManagementManager.RegisterNewPayment(
                    txtDoctorId.Text,
                    txtPatientId.Text,
                    cbxConcept.SelectedIndex.ToString(),
                    //txtConcept.Text,
                    //txtDate.Text,
                    fecha,
                    txtAmount.Text,
                    cbxPaymentMethod.SelectedIndex.ToString(),
                    //txtPaymentMethod.Text,
                    //txtPaymentState.Text,
                    txtDiscount.Text
                );
                DataAccess.ConsultationDataAccess.UpdateConsultation(txtAppointmentId.Text);
                MessageBox.Show("Pago registrado exitosamente");
                this.Dispose();
            }
            catch (Exception)
            {
                //MessageBox.Show("Error " + ex);
                labelMessage.Text = "Todos los campos son requeridos";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //SearchAppointmentPayment searchAppointmentForm;
            //searchAppointmentForm = new SearchAppointmentPayment(this);
            SearchConsultationPayment searchAppointmentForm;
            searchAppointmentForm = new SearchConsultationPayment(this);

            //searchAppointmentForm.Visible = true;
            searchAppointmentForm.ShowDialog();

            txtPatientId.Text = PatientId;
            txtDoctorId.Text = DoctorId;
            txtAppointmentId.Text = AppointmentId;
            txtDate.Text = DateAppointment;

            if (string.IsNullOrEmpty(PatientId) ||
                string.IsNullOrEmpty(DoctorId) ||
                string.IsNullOrEmpty(AppointmentId))
            {
            }
            else
            {
                btnGuardar.Enabled = true;
                btnGuardar.Visible = true;

                //Model.User doctor = Business.UserManager.ShowUser(txtDoctorId.Text);

                Model.User doctor = DataAccess.UserDataAccess.GetUserById(txtDoctorId.Text);
                txtDoctorName.Text = doctor.FirstName + " " + doctor.LastName;

                Model.Patient patient = Business.PatientManager.ShowPatient(txtPatientId.Text);
                txtPatientName.Text = patient.FirstName + " " + patient.FatherLastName;
                cbxConcept.SelectedText = "CONSULTA";

                
                
                string[] splittedDate;
                if (!string.IsNullOrEmpty(DateAppointment))
                {
                    splittedDate = DateAppointment.Split('/');
                    string dias = splittedDate[2];
                    string meses = splittedDate[1];
                    string anios = splittedDate[0];

                    dateTimePickerPayment.Value = new DateTime(Int16.Parse(anios), Int16.Parse(meses), Int16.Parse(dias));

                }
                //string fecha = "2011/05/01";
                               
                


                /*dateTimePicker1.Value.AddYears(Int16.Parse(anios));
                dateTimePicker1.Value.AddMonths(Int16.Parse(meses));
                dateTimePicker1.Value.AddDays(Int16.Parse(dias));
                */



                //cbxConcept.Items.F

                //btnRegistrarInsumos.Enabled = true;
                //btnRegistrarInsumos.Visible = true;

                /*btnRegistrarReceta.Enabled = true;
                btnRegistrarReceta.Visible = true;

                btnVerInsumos.Visible = true;

                btnVerInsumos.Enabled = true;
                btnVerInsumos.Visible = true;

                tabDatosPaciente.Enabled = true;
                tabDatosConsulta.Enabled = true;*/

            }
        }
    }
}
